package cn.fiker.lib.pageBar;

import java.util.EventObject;

public class pageEvent extends EventObject {

	private static final long serialVersionUID = 1568453962206707225L;

	public static final int EVENT_PAGE_LAST = 1;
	public static final int EVENT_PAGE_PREV = 2;
	public static final int EVENT_PAGE_NEXT = 3;
	public static final int EVENT_PAGE_FIRST = 4;
	public static final int EVENT_PAGE_GOTO = 5;

	private int code;
	private int page;

	public pageEvent(Object source) {
		super(source);
	}

	public int getEventCode() {
		return this.code;
	}

	public int getEventPage() {
		return this.page;
	}

	public void onPageEvent(pageEvent e) {
		switch (e.getEventCode()) {
		case EVENT_PAGE_NEXT:
			this.onNextPage(e);
			break;
		case EVENT_PAGE_PREV:
			this.onPrevPage(e);
			break;
		case EVENT_PAGE_LAST:
			this.onLastPage(e);
			break;
		case EVENT_PAGE_FIRST:
			this.onFirstPage(e);
			break;
		case EVENT_PAGE_GOTO:
			this.onGotoPage(e, this.getEventPage());
			break;
		}
	}

	public void onFirstPage(pageEvent e) {
		this.code = EVENT_PAGE_FIRST;
	}

	public void onPrevPage(pageEvent e) {
		this.code = EVENT_PAGE_PREV;
	}

	public void onNextPage(pageEvent e) {
		this.code = EVENT_PAGE_NEXT;
	}

	public void onLastPage(pageEvent e) {
		this.code = EVENT_PAGE_LAST;
	}

	public void onGotoPage(pageEvent e, int page) {
		this.page = page;
		this.code = EVENT_PAGE_GOTO;
	}

}